# coding=utf-8
import arcpy
import os

aprx = arcpy.mp.ArcGISProject(
    r"D:\BaiduNetdiskWorkspace\德安县土规延续和控规调整\德安县土规延续和控规调整.aprx")
lyt = aprx.listLayouts("布局")[0]
map = aprx.listMaps("地图")[0]
lyr = map.listLayers("土规延续项目汇总1213")[0]
rows = arcpy.SearchCursor(lyr, '', '', '', '项目名称')


def files_name(dirpath):
    for root, dirs, files in os.walk(dirpath):
        return files


namelist = files_name(r"D:\\BaiduNetdiskWorkspace\\德安县项目附图\\影像图")

for row in rows:
    # i = ['29','37']
    # if row.getValue("Layer") in i:
    name = row.getValue("项目名称")+".jpg"
    if name not in namelist:
        lyr.definitionQuery = "项目名称= " + "'" + row.getValue("项目名称") + "'"
        mf = lyt.listElements("MAPFRAME_ELEMENT", "地图框")[0]
        extent = mf.getLayerExtent(lyr, "False", "True")
        mf.camera.setExtent(extent)
        mf.camera.scale = mf.camera.scale*1.5
        lyt.exportToJPEG(r"D:\\BaiduNetdiskWorkspace\\德安县项目附图\影像图\\" +
                         row.getValue("项目名称"), resolution=150)
        lyr.definitionQuery = ""
del rows
del aprx
